<template>
  <div>
    <HomeHeader></HomeHeader>
    <HomeSwiper :swiperList="swiperList"></HomeSwiper>
    <HomeIcons :iconList="iconList"></HomeIcons>
    <Recommmend :recommendList="recommendList"></Recommmend>
    <weekend :weekendList="weekendList"></weekend>
  </div>
</template>

<script>
import HomeHeader from './components/header'
import HomeSwiper from './components/swiper'
import HomeIcons from './components/icons'
import Recommmend from './components/recommend'
import weekend from './components/weekend'
import axios from 'axios'
import { mapState } from 'Vuex'

export default {
  name: 'home',
  data: function () {
    return {
      lastCity: '',
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: []
    }
  },
  components: {
    HomeHeader: HomeHeader,
    HomeSwiper: HomeSwiper,
    HomeIcons: HomeIcons,
    Recommmend: Recommmend,
    weekend: weekend
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo: function () {
      axios.get('/api/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc: function (res) {
      res = res.data
      if (res.ret && res) {
        // this.city = res.data.city
        this.swiperList = res.data.swiperList
        this.iconList = res.data.iconList
        this.recommendList = res.data.recommendList
        this.weekendList = res.data.weekendList
      }
    }
  },
  mounted: function () {
    this.lastCity = this.city
    this.getHomeInfo()
  },
  activated: function () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
      console.log('keep-alive 再次执行')
    }
  }
}
</script>

<style lang="stylus" scoped>
@import "../../assets/style/varible.styl"
.index{
  color: $bg;
  font-size: 1.4rem;
}
</style>
